package com.slz3.business.frame.steward;

import com.slz3.business.frame.response.RR;
import org.springframework.web.reactive.function.server.ServerRequest;

import javax.validation.ConstraintViolation;
import java.util.Set;

public class HibernateValidatorSteward {

    public static <T> void constraintViolations(ServerRequest req, Set<ConstraintViolation<T>> constraintViolations) {
        if (constraintViolations.size() > 0) {
            constraintViolations.iterator().forEachRemaining(constraintViolation -> {
                String detailKey = constraintViolation.getRootBeanClass().getSimpleName()
                        .concat(".").concat(constraintViolation.getPropertyPath().toString());
                String detailVal = constraintViolation.getMessage();
                RR.resDetail(req).put(detailKey, detailVal);
            });
        }
    }

}
